package com.acceptable.qucun.file.mapper;

import com.acceptable.qucun.file.entity.FileShare;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.lang.NonNull;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 巴斯罗斯·K·赫斯洛利
 * @since 2021-08-29
 */
@Mapper
public interface FileShareMapper extends BaseMapper<FileShare> {

//    @Delete("DELETE FROM file_share WHERE user_id=#{share.userId} AND share_id=#{share.shareId} ")
//    int deleteByUserIdAndShareId(@NonNull @Param("share") FileShare share);

    FileShare selectByUrl(@NonNull @Param("url") String url);

    int insertBatch(@NonNull @Param("shareList") List<FileShare> shareList);

    @Select("SELECT share_id, share_time, expire_time, password, user_id, url " +
            "FROM file_share " +
            "WHERE user_id=#{userId}")
    List<FileShare> selectByUserId(@NonNull @Param("userId") Integer userId);

    @Delete("DELETE FROM file_share WHERE user_id=#{userId}")
    int deleteBatchByUserId(@NonNull @Param("userId") Integer userId);
}
